import { deleteRepuest, get, post, put } from "@/common/useAxios";
import Cookies from "js-cookie";

export interface ParamMenuModel {
  tid: string; //菜单编号
  fid: string | null; //父级菜单Id（为空表示根目录）
  mc: string; //菜单名称
  lj: string; //菜单路径
  tb: string; //菜单图标路径
  xh?: number; //排序序号
  lx: string; //菜单类型（1 生物城 2造价咨询 3设计）
  sfxs?: number; //是否显示到首页左侧菜单栏（1/true：显示；0/false：不显示）
  tzfs: string; //跳转方式
  qxlx: string; //权限类型，1、页面 2、按钮 3、数据
  qxbm: string; //权限标识
  dzgjz: string; //菜单地址key /关键字
  tbdz: string; //菜单图标选中路径
  children: ParamMenuModel[];
  // key: "19c8bd1d"
  // title: "首页"
  // value: "19c88"
}

export const getMenuList = (roleId: string) => {
  return get("/Menu/menuByRole/list", { roleId });
};

/**
 * 获取用户菜单列表
 * qxlx 1、页面 2、按钮 3、数据
 */
export const getUserMenuList = (qxlx: 1 | 2 | 3) => {
  return get("Qxgl/GetUserQxcd", { qxlx });
};

/**
 * 获取隐藏菜单
 */
export const GetHiddenMenuList = () => {
  const code = Cookies.get("showSystemConfigMenu");
  if (!code) return [];
  return get("Xtcd/GetHiddenMenuList", {
    code,
  });
};

/**
 * 根据角色id获取现有角色权限
 * @param jsId
 */
export const getPermissbyRole = (jsId: string) => {
  return get("Qxgl/getlist", { jsId });
};

/** 菜单列表分页 (获取全部的菜单列表)
 * @param name 关键字
 * @param jsgl 是否是角色管理菜单
 */
export let getMenuPageList = (name?: string, jsgl = false) => {
  return get("/xtcd/getlist", {
    name,
    jsgl,
  });
};

/**
 * 添加菜单
 * @returns
 */
export let addMenuModel = (param: ParamMenuModel) => {
  return post("/Menu/create", param);
};

/**
 * 编辑菜单
 * @returns
 */
export let editMenuModel = (param: ParamMenuModel) => {
  return put("/xtcd/EditXtcd", param);
};

/**
 * 删除菜单
 * @returns
 */
export let deleMenuModel = (sid: string) => {
  return deleteRepuest("/xtcd/DelXtcd", { sid });
};

/**
 * 调整菜单顺序
 * @returns
 */
export let CdMove = (cdid: string, moveup: boolean) => {
  return get("/xtcd/CdMove", { cdid, moveup }, { method: "post" });
};

/**
 * 加载父级菜单
 * @returns
 */
export let getLoadPartMenuId = () => {
  return get("/Project/Menu/GetLoadPartMenuId");
};

/**
 * 获取单位类型
 * @returns
 */
export let getUnitType = (state: number = 1) => {
  return get("/Menu/GetUnitType", { state });
};

/**
 * 获取有查看权限的单位类型
 * @returns
 */
export let getUnitTypeByUserInfo = () => {
  return get("Menu/GetUnitTypeByUserInfo");
};

/**
 * 系统配置菜单项口令验证
 * @returns
 */
export let verifyMenuPower = (code: string) => {
  return get("Menu/power/verify", { code });
};
